<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>为Vue组件传递数据</title>
    <!-- 引入vue.js -->
    <script src="vue/vue.js"></script>
</head>

<body>
    <div id="app-7">
        <my-post v-for="post in posts" :key="post.id" :title="post.title" :published="post.published"></my-post>
    </div>
    <script>

        Vue.component('my-post', {
            props: ['title', 'published'],
            template: '<div><h3>{{title}}</h3><p>{{published}}</p></div>  '
        })

        var app7 = new Vue({
            el: '#app-7',
            data: {
                posts: [
                    { id: 1, title: '标题1', published: '2020-5-11' },
                    { id: 2, title: '标题2', published: '2020-5-21' },
                    { id: 3, title: '标题3', published: '2020-5-13' },
                ]
            }
        })
    </script>
</body>

</html>
